<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .nav-header {
            width: 500px;
            height: 100px;
            /* background-color: gray; */
            margin: 0 auto;
        }

        .nav-header ul {
            display: flex;
            padding: 0;
            
        }

        ul li {
            list-style: none;
            width: 100px;
            text-align: center;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
        }

        .slider {
            height: 2px;
            width: 100px;
            background-color: red;
            transition: all 0.3s;
        }


    </style>
</head>
<body>

    <div class="nav-header">
        <ul>
            <li data-id="0">首页</li>
            <li data-id="1">动画</li>
            <li data-id="2">番剧</li>
            <li data-id="3">国创</li>
            <li data-id="4">鬼畜</li>
        </ul>

        <div class="slider"></div>
    </div>

<script>
    let ul = document.querySelector("ul")
    let slide = document.querySelector(".slider")
    ul.addEventListener("click", function(e) {
        let id = e.target.dataset.id
        console.log(e.target)
        slide.style.transform = `translateX(${100 * id}px)`
        console.log()

    })
</script>
</body>
</html>